package com.example.cat.catwidget;

import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.icu.text.SimpleDateFormat;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.RemoteViews;
import android.widget.TextView;

import com.example.cat.catwidget.Server.UpdateWidgetService;
import com.example.cat.catwidget.Utils.FileHelper;
import com.example.cat.catwidget.Utils.NewImgAdapter;
import com.example.cat.catwidget.Utils.PrintLogHelper;
import com.example.cat.catwidget.Utils.SharedPreferencesHelper;
import com.example.cat.catwidget.Utils.WidgetHelper;

import java.sql.Time;
import java.util.Date;
import java.util.Random;

public class SelectImgActivity extends AppCompatActivity {

    private GridView gridview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_img);
        //   mAppWidgetText = (EditText) findViewById(R.id.appwidget_text);
        // Find the widget id from the intent.


        //   mAppWidgetText.setText(loadTitlePref(SelectImgActivity.this, mAppWidgetId));
        InitView();
        InitNewGridView();


    }

    private void InitView() {
        gridview = findViewById(R.id.gridview);
    }

    private void InitNewGridView() {
        NewImgAdapter.TempImgInfoList = new FileHelper().GetAssetsList(this, "ImgFloder");

        NewImgAdapter TempAD = new NewImgAdapter();

        gridview.setAdapter(TempAD);                 //为数据源设置好适配器
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                PrintLogHelper.OutLog("点击选项" + i);
                SharedPreferencesHelper.SaveIntValueForWrite("WidgetInfo", "ImgIndex", i);
                WidgetHelper.UpdateView(new NewImgAdapter().GetBitMap(i));
                Intent home = new Intent(Intent.ACTION_MAIN);
                home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                home.addCategory(Intent.CATEGORY_HOME);
                startActivity(home);
                finish();
            }
        });

    }




}
